#ifndef BOARD_H
#define BOARD_H

#include <QWidget>
#include "stone.h"
#include <QPixmap>
#include <step.h>
#include <QMessageBox>

class board : public QWidget
{
    Q_OBJECT
public:
    explicit board(QWidget *parent = 0);

    void paintEvent(QPaintEvent *);

    stone _s[32];//定义32个棋子类对象

    int _r;//棋子的半径
    int _selectid;
    bool _bredturn;

    bool gameover;

    //返回棋盘行列对应的像素坐标
    QPoint center(int row,int col);
    QPoint center(int id);//重载！
    bool getrowcol(QPoint pt,int& row,int&mcol);

    void drawstone(QPainter& painter,int id);//不同id的棋子的绘制
    //为什么要用Qpainter的引用而不是Qpainter这个对象?
    //绘制的对象已经与窗口产生了关联，如果不用引用，painter传过来的时候就是一个拷贝成员变量

    void mouseReleaseEvent(QMouseEvent*);//鼠标事件

    bool canmove(int moveid,int row,int col,int killid);//行棋判定

    bool canmovejiang(int moveid,int row,int col,int killid);
    bool canmoveshi(int moveid,int row,int col,int killid);
    bool canmovexiang(int moveid,int row,int col,int killid);
    bool canmoveche(int moveid,int row,int col,int killid);
    bool canmovema(int moveid,int row,int col,int killid);
    bool canmovepao(int moveid,int row,int col,int killid);
    bool canmovebing(int moveid,int row,int col,int killid);

    int getid(int row,int col);
    int getstonecount(int row1,int col1,int row2,int col2);

    bool prxingqi=false;

    void savestep(int moveid,int killid,int row,int col,QVector<step*>&steps);
    void backstep();//悔棋函数
    QVector<step*> steps;//保存行棋过程

    void relivestone();//“复活”棋子
    void resetstone();//重置位置

    void writechuhan(QPainter &painter);//写楚河汉界
    void drawbasicboard(QPainter &painter);//画线
    void writexingqi(QPainter &painter);//行棋一方
    void writewin(QPainter &painter);//胜负输出



signals:

public slots:
    void printshuoming();
    void printxingqi(){
        prxingqi=!prxingqi;
    }

};

#endif // BOARD_H
